<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\Store
 *
 * @property int $id
 * @property string|null $background 背景图片，多张逗号隔开
 * @property string $name 店铺名称
 * @property string $logo 店铺logo
 * @property string $phone 联系人手机号
 * @property string $area 地址
 * @property string $longitude 经度
 * @property string $latitude 纬度
 * @property string $province_name 省名称
 * @property string $province_code 省代码
 * @property string $city_name 市名称
 * @property string $city_code 市代码
 * @property int $is_close 1正常，0关闭店铺
 * @property float $discount 折扣
 * @property float $total_money 商家在平台的总收益
 * @property float $usable_money 商家在平台的可提现金
 * @property float $total_card_ticket_money 用户卡卷总共消费金额
 * @property string|null $deleted_at
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property int|null $category_id 店铺分类
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereArea($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereBackground($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereCategoryId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereCityCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereCityName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereDiscount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereIsClose($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereLatitude($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereLogo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereLongitude($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store wherePhone($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereProvinceCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereProvinceName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereTotalCardTicketMoney($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereTotalMoney($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Store whereUsableMoney($value)
 * @mixin \Eloquent
 */
class Store extends Model
{
    const TABLE = 'store';
    protected $table = self::TABLE;

    public static function distance($longitude, $latitude, $lonColumnName = "longitude", $latColumnName = "latitude")
    {
        return "ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(($latitude * PI() / 180 - `$latColumnName` * PI() / 180) / 2), 2) + COS(`$latColumnName` * PI() / 180) * COS(`$latColumnName` * PI() / 180) * POW(SIN(($longitude * PI() / 180 - `$lonColumnName` * PI() / 180) / 2), 2))) * 1000) as distance";
    }
}
